home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / text / edit / tecoc-146.lha / makrom.c < prev    next >
C/C++ Source or Header  |  1991-07-05  |  2KB  |  59 lines

  1. /*****************************************************************************
  2.  
  3.     MakRom()
  4.  
  5.     This function "makes room" in a q-register text area for new text.
  6. If the text area was empty,  this function simply calls ZAlloc to allocate
  7. new memory.  If the text area was not empty,  this function calls ZRaloc to
  8. add more memory to the text area.  In either case, the Amount argument
  9. specifies how much memory to add to the existing text area.
  10.  
  11.     On entry,  QR->Start points to the start of the text area (or NULL if
  12. the text area was empty) and QR->End_P1 points to the end of the text area.
  13. On return,  QR->Start points to the start of the text area and QR->End_P1
  14. points to the BEGINNING of the newly allocated memory.  This is because the
  15. caller knows where the end is and is expected to reset QR->End_P1 after it
  16. is used as the destination of the new text.
  17.  
  18.     Note:  the Amount argument is assumed to be greater than 0.
  19.  
  20. *****************************************************************************/
  21.  
  22. #include "zport.h"        /* define portability identifiers */
  23. #include "tecoc.h"        /* define general identifiers */
  24. #include "defext.h"        /* define external global variables */
  25. #include "deferr.h"        /* define identifiers for error messages */
  26.  
  27. DEFAULT MakRom(Amount)        /* make room in q-register */
  28. SIZE_T Amount;            /* how much additional room to make */
  29. {
  30.     ptrdiff_t    OldSiz;        /* old size of text area */
  31.     charptr        NewBlk;        /* new text area */
  32.  
  33. #if DEBUGGING
  34.     static char *DbgFNm = "MakRom";
  35.     sprintf(DbgSBf,"Amount = %ld bytes", (LONG)Amount);
  36.     DbgFEn(2,DbgFNm,DbgSBf);
  37. #endif
  38.     if (QR->Start == NULL) {        /* if it was empty */
  39.         OldSiz = 0;
  40.         NewBlk = (charptr)ZAlloc(Amount);
  41.     } else {
  42.         OldSiz = QR->End_P1 - QR->Start;
  43.         NewBlk = (charptr)ZRaloc(QR->Start, OldSiz + Amount);
  44.     }
  45.  
  46.     if (NewBlk == NULL) {            /* if ZAlloc/ZRaloc failed */
  47.         ErrMsg(ERR_MEM);        /* ERR = memory overflow */
  48.         DBGFEX(2,DbgFNm,"FAILURE");
  49.         return FAILURE;
  50.     }
  51.  
  52.     QR->Start  = NewBlk;
  53.     QR->End_P1 = NewBlk + OldSiz;
  54.  
  55.     DBGFEX(2,DbgFNm,"SUCCESS");
  56.  
  57.     return SUCCESS;
  58. }
  59.